import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Graph
df1=pd.read_excel('关系图.xlsx',sheet_name='dslajgoia')
list_nodes=df1.to_dict(orient='records')
print(list_nodes)
df2=pd.read_excel('关系图.xlsx',sheet_name='dslajgoia1')
list_links=df2.to_dict(orient='records')
print(list_links)
df3=pd.read_excel('关系图.xlsx',sheet_name='dslajgoia2')
list_categorys=df3.to_dict(orient='records')
print(list_categorys)

graph=Graph(init_opts=opts.InitOpts(
    width='759px',height='700px',page_title='关系图'
))

graph.add(series_name='',nodes=list_nodes,links=list_links,
          categories=list_categorys,repulsion=8000,edge_label=opts.LabelOpts(
        position='middle',formatter='{b} {c}'))

graph.set_global_opts(title_opts=opts.TitleOpts(
    title='《红楼梦》中部分人物关系图',pos_left='center'),
    legend_opts=opts.LegendOpts(
        pos_top='50%',pos_right='1%',orient='vertical')
)
graph.render('8-3.html')